﻿
using System.Collections.Generic;
using System.Text;
using Nop.Core.Html;

namespace Nop.Plugin.Misc.DynamicsCrm.Services
{
    public class SyncResult
    {
        public SyncResult()
        {
            EmailErrors = new List<string>();
            ContactErrors = new List<string>();
            NewsLetterSubscriptionErrors = new List<string>();
            OrderErrors = new List<string>();
        }

       
        public string EmailResult { get; set; }
        public string ContactResult { get; set; }
        public string NewsLetterSubscriptionResult { get; set; }
        public string OrderResult { get; set; }

        public string ConnectionError { get; set; }
        public List<string> EmailErrors { get; set; }
        public List<string> ContactErrors { get; set; }
        public List<string> NewsLetterSubscriptionErrors { get; set; }
        public List<string> OrderErrors { get; set; }

        public string ToHtml()
        {
            var sb = new StringBuilder();

            //Connection
            if (!string.IsNullOrEmpty(this.ConnectionError))
            {
                sb.Append("Connection error: ");
                sb.Append(HtmlHelper.ConvertPlainTextToHtml(this.ConnectionError));
                sb.Append("<br />");
            }

            //Email
            sb.Append("Email results: ");
            sb.Append(HtmlHelper.ConvertPlainTextToHtml(this.EmailResult));
            sb.Append("<br />");
            for (int i = 0; i < this.EmailErrors.Count; i++)
            {
                sb.Append(HtmlHelper.ConvertPlainTextToHtml(this.EmailErrors[i]));
                if (i != this.EmailErrors.Count - 1)
                    sb.Append("<br />");
            }

            sb.Append("<br />");

            //Contact
            sb.Append("Contact results: ");
            sb.Append(HtmlHelper.ConvertPlainTextToHtml(this.ContactResult));
            sb.Append("<br />");
            for (int i = 0; i < this.ContactErrors.Count; i++)
            {
                sb.Append(HtmlHelper.ConvertPlainTextToHtml(this.ContactErrors[i]));
                if (i != this.ContactErrors.Count - 1)
                    sb.Append("<br />");
            }

            sb.Append("<br />");

            //NewsLetterSubscription
            sb.Append("NewsLetterSubscription results: ");
            sb.Append(HtmlHelper.ConvertPlainTextToHtml(this.NewsLetterSubscriptionResult));
            sb.Append("<br />");
            for (int i = 0; i < this.NewsLetterSubscriptionErrors.Count; i++)
            {
                sb.Append(HtmlHelper.ConvertPlainTextToHtml(this.NewsLetterSubscriptionErrors[i]));
                if (i != this.NewsLetterSubscriptionErrors.Count - 1)
                    sb.Append("<br />");
            }

            sb.Append("<br />");

            //Order
            sb.Append("Order results: ");
            sb.Append(HtmlHelper.ConvertPlainTextToHtml(this.OrderResult));
            sb.Append("<br />");
            for (int i = 0; i < this.OrderErrors.Count; i++)
            {
                sb.Append(HtmlHelper.ConvertPlainTextToHtml(this.OrderErrors[i]));
                if (i != this.OrderErrors.Count - 1)
                    sb.Append("<br />");
            }

            return sb.ToString();
        }
    }
}